﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.AddIn.Hosting;
using System.Collections.ObjectModel;
using ScenarioFramework.AddIns.HostView;

namespace ScenarioFramework.AddIns.AddInsManager
{
    class Program
    {
        static void Main(string[] args)
        {
            // Set the add-ins discovery root directory to be the current directory
            string addinRoot = Environment.CurrentDirectory;

            // Rebuild the add-ins cache and pipeline components cache. 
            string[] results = AddInStore.Rebuild(addinRoot);
            foreach (string s in results)
            {
                Console.WriteLine(s);
            }

            // Get registerd add-ins of type SimpleAddInHostView
            Collection<AddInToken> addins = AddInStore.FindAddIns(typeof(SimpleAddInHostView), addinRoot);

            foreach (AddInToken addinToken in addins)
            {
                // Activate the add-in
                SimpleAddInHostView addinInstance = addinToken.Activate<SimpleAddInHostView>(AddInSecurityLevel.Internet);

                // Use the add-in
                Console.WriteLine(String.Format("Add-in {0} Version {1}", addinToken.Name, addinToken.Version));
                Console.WriteLine(addinInstance.SayHello("Guy"));
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }
    }
}
